#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5; 
long long z[N],n,m,q,a[N],b[N][10],ans1,l,r,opt,sum;
struct node{
	long long a[6][6];
}tree[N*4+5],ans;
node hb(node i,node j)
{
	node z;
	for(int ii=0;ii<=m;++ii)
		for(int jj=0;jj<=m;++jj)
			z.a[ii][jj]=-1e18;
	for(int ii=0;ii<=m;++ii)
		for(int jj=0;jj<=m;++jj)
			for(int zz=0;zz<=m;++zz)
				z.a[ii][jj]=max(z.a[ii][jj],i.a[ii][zz]+j.a[zz][jj]);
	return z;
}
node hb1(node i,node j)
{
	node z;
	for(int ii=0;ii<=m;++ii)
		for(int jj=0;jj<=m;++jj)
			z.a[ii][jj]=-1e18;
	for(int ii=0;ii<=m;++ii)
		for(int jj=0;jj<=m;++jj)
				z.a[0][jj]=max(z.a[0][jj],i.a[0][ii]+j.a[ii][jj]);
	return z;
}
void build(int l,int r,int id)
{
	if(l==r)
	{
		for(int i=0;i<=m;++i)
			for(int j=0;j<=m;++j)
				tree[id].a[i][j]=-1e18;
		tree[id].a[0][0]=b[l][a[l]];
		tree[id].a[1][1]=b[l][1];
		tree[id].a[2][2]=b[l][2];
		tree[id].a[3][3]=b[l][3];
		tree[id].a[4][4]=b[l][4];
		tree[id].a[5][5]=b[l][5];
		tree[id].a[a[l]][0]=b[l][a[l]];
		tree[id].a[0][a[l]]=b[l][a[l]];
		return;
	}
	int mid=(l+r)/2;
	build(l,mid,id*2);
	build(mid+1,r,id*2+1);
	tree[id]=hb(tree[id*2],tree[id*2+1]);
}
void xg(int l,int r,int nn,int id)
{
	if(l==r)
	{
		for(int i=0;i<=m;++i)
			for(int j=0;j<=m;++j)
				tree[id].a[i][j]=-1e18;
		tree[id].a[0][0]=b[l][a[l]];
		tree[id].a[1][1]=b[l][1];
		tree[id].a[2][2]=b[l][2];
		tree[id].a[3][3]=b[l][3];
		tree[id].a[4][4]=b[l][4];
		tree[id].a[5][5]=b[l][5];
		tree[id].a[a[l]][0]=b[l][a[l]];
		tree[id].a[0][a[l]]=b[l][a[l]];
		return;
	}
	int mid=(l+r)/2;
	if(mid>=nn) xg(l,mid,nn,id*2);
	else xg(mid+1,r,nn,id*2+1);
	tree[id]=hb(tree[id*2],tree[id*2+1]);
}
void cz(int l,int r,int nl,int nr,int id)
{
	if(nl<=l&&r<=nr)
	{
		ans=hb1(ans,tree[id]);
		return;
	}
	int mid=(l+r)/2;
	if(mid>=nl) cz(l,mid,nl,nr,id*2);
	if(mid<nr) cz(mid+1,r,nl,nr,id*2+1);
}
int main()
{
	freopen("paint.in","r",stdin); 
	freopen("paint.out","w",stdout); 
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>q;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			cin>>b[i][j];
	build(1,n,1);
	for(int i=0;i<=m;++i)
		for(int j=0;j<=m;++j)
			ans.a[i][j]=-1e18;
	ans.a[0][0]=0;
	cz(1,n,1,n,1);
	ans1=ans.a[0][0];
	cout<<ans1<<'\n';
	for(int i=1;i<=q;++i)
	{
		cin>>opt>>l>>r;
		l^=ans1;
		r^=ans1;
		if(opt==1)
		{
			a[l]=r;
			xg(1,n,l,1);
		}
		else
		{
			for(int j=1;j<=m;++j)
				ans.a[0][j]=-1e18;
			ans.a[0][0]=0;
			cz(1,n,l,r,1);
			ans1=ans.a[0][0];
			cout<<ans1<<'\n';
		}
	}
	return 0;
 } 
